<template>
    <div class="console-page">
        <interfaceDoc :interfaceInfo="interfaceInfo" style="background: rgba(255, 255, 255, .1) !important;" />
    </div>
</template>

<script setup>
import { useRequest } from "@usehook"
import router from "@/router"

let interfaceInfo = $ref({
    name: '',
    url: '',
    params: [],
    comments: '',
    code: '',
    status: 0,
    sequence: null,
    method: "get",
    returnType: "auto",
    type: 'sql',
    checkPermission: 1,
    requestLock: 0,
    useCache: 60,
    apiType: 0,
    encrypt: 0
})

const getInterfaceInfo = () => {
    const route = router.currentRoute.value;
    const sequence = route.query.sequence;
    useRequest({ url: "/interface/detail", sequence: sequence }).then(resData => {
        if (resData && resData.status) {
            const data = resData.data;
            if (data) {
                const params = JSON.parse(data.params || '{}')
                interfaceInfo.params = Object.keys(params).map(e => params[e]);
                interfaceInfo.name = data.interfaceName;
                interfaceInfo.code = data.code;
                interfaceInfo.status = data.status;
                interfaceInfo.sequence = data.sequence;
                interfaceInfo.method = data.method;
                interfaceInfo.comments = data.comments;
                interfaceInfo.url = data.url
                interfaceInfo.returnType = data.returnType;
                interfaceInfo.type = data.type;
                interfaceInfo.checkPermission = data.checkPermission
                interfaceInfo.requestLock = data.requestLock
                interfaceInfo.encrypt = data.encrypt
                interfaceInfo.useCache = data.useCache
                interfaceInfo.apiType = data.apiType
            }
        }
    });
}

onMounted(() => {
    getInterfaceInfo()
})
</script>